#include <pthread.h>
#include <stdio.h>
#include <limits.h>
pthread_mutex_t mutex_lock=PTHREAD_MUTEX_INITIALIZER;
long long int g_count;
void* threadF(void* data){
char* thread_name=(char*)data;
pthread_mutex_lock(&mutex_lock);
printf("%s start: g_count=%lld\n", thread_name, g_count);
for(int i=INT_MIN; i<INT_MAX; ++i) g_count++;
printf("%s end: g_count=%lld\n", thread_name, g_count);
pthread_mutex_unlock(&mutex_lock);
}
int main(void){
pthread_t pthread[3];
int status;
pthread_create(&pthread[0], NULL, threadF, (void*)"Thread1");
pthread_create(&pthread[1], NULL, threadF, (void*)"Thread2");
pthread_create(&pthread[2], NULL, threadF, (void*)"Thread3");
pthread_join(pthread[0], (void*)&status);
pthread_join(pthread[1], (void*)&status);
pthread_join(pthread[2], (void*)&status);
return 0;
}